import 'package:app/services/address.dart';
import 'package:app/services/dio_manager.dart';
import 'package:bot_toast/bot_toast.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter_easyrefresh/easy_refresh.dart';
import 'package:get/get.dart';
import 'cooperate_model.dart';

class CooperateController extends GetxController{

  var page = 1;

  List dataArr = [];
  TextEditingController searchTextEditingController = TextEditingController();

  EasyRefreshController easyRefreshController = EasyRefreshController();

  requestData({var search})async{
    var params = {
      'page':page,
      'limit':10,
      'search':search,
    };
    var json = await DioManager().kkRequest(Address.hrEmployeePage,params: params,method: 'get');

    CooperateModel model = CooperateModel.fromJson(json);

    if(page == 1){
      easyRefreshController.resetLoadState();
      dataArr.clear();
      if(model.data != null){
        dataArr.addAll(model.data!);
      }
    }else{
      if(model.data!= null){
        dataArr.addAll(model.data!);
      }else{
        BotToast.showText(text: '暂无更多');
        easyRefreshController.finishLoad(noMore: true);
      }
    }

    update();
  }


  onRefresh()async{
    page = 1;
    requestData(search: searchTextEditingController.text);
  }
  onLoad()async{
    page++;
    requestData(search: searchTextEditingController.text);
  }

  @override
  void onInit() {
    // TODO: implement onInit
    super.onInit();
    requestData();
  }


}